/**
 * 
 */
package jmine.tec.report.cell.impl;

import java.io.Serializable;
import java.text.NumberFormat;

/**
 * Celula que soma. É um singleton pois celulas funcao nao precisam de estados.
 * 
 * @author takeshi
 */
public final class SumFunctionDataCell extends AbstractDoubleFunctionDataCell implements Serializable {

    private static final long serialVersionUID = -6236355626773029294L;

    private final NumberFormat numberFormat;

    /**
     * @param numberFormat the {@link NumberFormat}
     */
    public SumFunctionDataCell(NumberFormat numberFormat) {
        super();
        this.numberFormat = numberFormat;
    }

    /**
     * Default constructor
     */
    public SumFunctionDataCell() {
        this(null);
    }

    /**
     * Returns the single instance of this class, lazy loading if necessary
     * 
     * @return the single instance
     */
    public static SumFunctionDataCell getInstance() {
        return new SumFunctionDataCell();
    }

    /**
     * @param values os valores
     * @return double
     * @see br.com.maps.util.report.cell.impl.AbstractDoubleFunctionDataCell#combine(double[])
     */
    @Override
    protected double combine(final double... values) {
        double combine = 0;
        for (double d : values) {
            combine += d;
        }
        return combine;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected NumberFormat getNumberFormat() {
        return this.numberFormat;
    }
}
